package com.llh.cheap.configs;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.qxt.department.UserDepartmentInfoProvider;
import com.qxt.department.UserPositionInfoProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import top.moirae.core.ResultMap;

@Configuration
@ComponentScan(basePackages = "com.llh.cheap")
@PropertySource("classpath:app.properties")
public class BusinessConfig {

    @Bean
    public ResultMap<Long> userMetaInfo(UserDepartmentInfoProvider departmentInfoProvider, UserPositionInfoProvider userPositionInfoProvider) {
        ResultMap<Long> resultMap = new ResultMap<>();
        resultMap.addProvider(departmentInfoProvider);
//        resultMap.addProvider(residentInfoProvider);
        resultMap.addProvider(userPositionInfoProvider);
        return resultMap;
    }

    @Bean
    public WxMaService wxMaService(
            @Value("${wx.miniapp.appid}") String appId,
            @Value("${wx.miniapp.secret}") String secret,
            @Value("${wx.miniapp.token}") String token,
            @Value("${wx.miniapp.aesKey}") String aesKey,
            @Value("${wx.miniapp.msgDataFormat}") String msgDataFormat
    ) {
        WxMaService wxMaService = new WxMaServiceImpl();
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
        wxMaConfig.setAppid(appId);
        wxMaConfig.setSecret(secret);
        wxMaConfig.setToken(token);
        wxMaConfig.setAesKey(aesKey);
        wxMaConfig.setMsgDataFormat(msgDataFormat);
        wxMaService.setWxMaConfig(wxMaConfig);
        return wxMaService;
    }


}
